<%--
  Created by IntelliJ IDEA.
  User: wangbin
  Date: 2015/3/3
  Time: 9:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="../inc/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <%@ include file="../inc/meta.jsp" %>
    <meta name="description" content="">
    <meta name="author" content="">
    <title>客户列表</title>
    <%@ include file="../inc/css.jsp" %>

</head>

<body>

<div id="posts" class="wrapper">

    <%@ include file="../inc/nav.jsp" %>

    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">客户列表</h1>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">

                        <a href="admin/customer/edit" class="btn btn-outline btn-primary btn-lg"
                           role="button"><i class="fa fa-plus"></i> 新增客户</a>

                        <a href="javascript:;" onclick="$customer.fn.exportExl()" class="btn btn-outline btn-primary btn-lg"
                           role="button"><i class="fa fa-file-excel-o"></i> 导出</a>

                        <form class="navbar-form navbar-right" role="search">

                            <div class="form-group">
                                <input type="text" style="width: 250px;" id="searchContent" class="form-control" placeholder="需求号/客户名称/手机号/分配操作员">
                            </div>

                            <div class="form-group">
                                <label>等级：</label>
                                <select class="form-control input-sm" id="grade">
                                    <option value="">--请选择--</option>
                                    <option value="A">A</option>
                                    <option value="B">B</option>
                                    <option value="C">C</option>
                                    <option value="D">D</option>
                                    <option value="FAIL">战败</option>
                                </select>
                            </div>

                            <div class="form-group">
                                <label>最后联系时间：</label>
                                <input type="text" id="createDate" class="form-control input-append date form_datetime" style="width: 180px;"
                                       readonly  value="" placeholder="最后联系时间">
                            </div>

                            <button type="button" id="c_search" class="btn btn-default btn-sm">查询</button>
                            <button type="button" id="c_clear" class="btn btn-default btn-sm">清空</button>
                        </form>
                    </div>
                    <!-- /.panel-heading -->
                    <div class="panel-body">

                        <div class="table-responsive">

                            <table class="table table-striped table-bordered table-hover" id="dataTables">
                                <colgroup>
                                    <col class="gradeA even"/>
                                    <col class="gradeA odd"/>
                                    <col class="gradeA even"/>
                                    <col class="gradeA odd"/>
                                    <col class="gradeA even"/>
                                    <col class="gradeA odd"/>
                                </colgroup>
                                <thead>
                                <tr>
                                    <th><input type="checkbox" onclick="$leoman.checkAll(this)" class="checkall"/></th>
                                    <th>需求号</th>
                                    <th>客户姓名</th>
                                    <th>客户手机号</th>
                                    <th>最后联系时间</th>
                                    <th>下次联系时间</th>
                                    <th>重要等级</th>
                                    <th>分配操作员</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                        </div>

                    </div>
                    <!-- /.panel-body -->

                </div>
                <!-- /.panel -->
            </div>
        </div>

    </div>
    <!-- /#page-wrapper -->

</div>
<!-- /#wrapper -->

<!-- 选择指派管理员弹出框 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="pwdModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">请选择要指派的操作员</h4>
            </div>
            <div class="modal-body">
                <form class="cmxform form-horizontal adminex-form" enctype="multipart/form-data">

                    <input type="hidden" id="customerId" value="">

                    <select class="form-control input-sm" id="adminId" style="width: 200px;">
                        <c:forEach items="${adminList}" var="admin">
                            <option value="${admin.id}">${admin.name}</option>
                        </c:forEach>
                    </select>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" onclick="$customer.fn.selectAdmin()" class="btn btn-primary">确定</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>

<%@ include file="../inc/footer.jsp" %>
</body>

<script>
    $customer = {
        v: {
            list: [],
            dTable: null
        },
        fn: {
            init: function () {
                $customer.fn.dataTableInit();
                $("#c_search").click(function () {
                    $customer.v.dTable.ajax.reload();
                });

                $("#c_clear").click(function () {
                    $(".navbar-form").find("input, select").val("");
                });

                $('.form_datetime').datetimepicker({
                    language: 'zh-CN',
                    weekStart: 1,
                    todayBtn: 1,
                    autoclose: 1,
                    todayHighlight: 1,
                    minView: 'month',
                    forceParse: 0,
                    showMeridian: false,
                    format: 'yyyy-mm-dd'
                });
            },
            dataTableInit: function () {
                $customer.v.dTable = $leoman.dataTable($('#dataTables'), {
                    "processing": true,
                    "serverSide": true,
                    "searching": false,
                    "bSort": false,
                    "ajax": {
                        "url": "${contextPath}/admin/customer/list",
                        "type": "POST"
                    },
                    "columns": [
                        {
                            "data": "id",
                            "render": function (data) {
                                var checkbox = "<input type='checkbox' class='list-check' onclick='$leoman.subSelect(this);' value=" + data + ">";
                                return checkbox;
                            }
                        },
                        {"data": "demandNo"},
                        {"data": "name"},
                        {"data": "mobile"},
                        {"data": "createDate"},
                        {"data": "nextTime"},
                        {"data": "grade"},
                        {"data": "adminName"},
                        {
                            "data": "id",
                            "render": function (data, type, row, meta) {

                                var btn = "<button title='查看' class='btn btn-primary edit' onclick=\"$customer.fn.detail(\'" + data + "\')\">" +
                                        "<i class='fa fa-eye'></i> 查看</button>";

                                if("${session_globle_member.roleId}" != 3){
                                    btn += "&nbsp;" + "<button title='编辑' class='btn btn-primary edit' onclick=\"$customer.fn.add(\'" + data + "\')\">" +
                                            "<i class='fa fa-pencil-square-o'></i> 编辑</button>";

                                    btn += "&nbsp;" + "<button title='指派' class='btn btn-primary edit' onclick=\"$customer.fn.openModal(\'" + data + "\')\">" +
                                            "<i class='fa fa-check'></i> 指派</button>";

                                    btn += "&nbsp;" + "<button title='删除' class='btn btn-primary edit' onclick=\"$customer.fn.del(\'" + data + "\')\">" +
                                            "<i class='fa fa-trash-o'></i> 删除</button>";
                                }

                                return btn;

                            }
                        }
                    ],
                    "fnServerParams": function (aoData) {
                        aoData.searchContent = $("#searchContent").val();
                        aoData.grade = $("#grade").val();
                        aoData.createDate = $("#createDate").val();
                    }
                });
            },
            //查看
            detail:function(id){
                window.location.href = "${contextPath}/admin/customer/info?id=" + id;
            },
            add: function (id) {
                var params = "";
                if (id != null && id != '') {
                    params = "?id=" + id;
                }
                window.location.href = "${contextPath}/admin/customer/edit" + params;
            },
            openModal : function(id){
                $("#customerId").val(id);
                $("#myModal").modal("show");
            },
            //保存选择的操作员
            selectAdmin : function(){
                var data = {
                    id : $("#customerId").val(),
                    adminId : $("#adminId option:selected").val()
                };
                $.post("${contextPath}/admin/customer/save", data, function(result){
                    if(result.status == 0){
                        window.location.reload();
                    }else{
                        $leoman.alertMsg(result.msg);
                    }
                });
            },
            del: function (id) {
                var checkBox = $("#dataTables tbody tr").find('input[type=checkbox]:checked');
                var ids = [];
                if(id != null){
                    ids.push(id);
                }else{
                    ids = checkBox.getInputId();
                }
                $leoman.alertConfirm("您确定要彻底删除所选的客户吗？",function(){
                    $.ajax({
                        "url": "${contextPath}/admin/customer/delete",
                        "data": {
                            ids:JSON.stringify(ids)
                        },
                        "dataType": "json",
                        "type": "POST",
                        success: function (result) {
                            if(result.status == 0){
                                window.location.reload();
                            }else{
                                $leoman.alertMsg(result.msg);
                            }
                        }
                    });
                });
            },
            //导出
            exportExl:function(){
                $leoman.alertConfirm("您确定要导出所筛选的数据吗？",function(){
                    var data = {
                        searchContent:$("#searchContent").val()
                    };
                    $leoman.subWebForm("${contextPath}/admin/customer/exportExl", data);
                    <%--window.location.href = "${contextPath}/admin/customer/exportExl?";--%>
                    /*$.ajax({
                        "url": "${contextPath}/admin/customer/exportExl",
                        "data": {
                            searchContent:$("#searchContent").val()
                        },
                        "dataType": "json",
                        "type": "POST",
                        success: function (result) {
                            if(result.status == 0){
                                window.location.reload();
                            }else{
                                $leoman.alertMsg(result.msg);
                            }
                        }
                    });*/
                });
            }
        }
    }
    $(function () {
        $customer.fn.init();
    })
</script>
</html>